<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function () {
            var input_element = document.getElementsByTagName("input");
            input_element[3].onclick = function () {
                var n = parseFloat(input_element[0].value);
                var k = parseFloat(input_element[1].value);
                var a = 1;//是次方的结果，初值为1
                var b = 1;//循环变量
                while (a <= k) {//循环条件（循环次数）
                    b = b * n;
                    a++;//循环变量的改变
                }
                input_element[2].value = b;
            }
            input_element[4].onclick = function () {
                var n = parseFloat(input_element[0].value);
                var k = parseFloat(input_element[1].value);
                var a = 1;
                var b = 1;
                do {
                    b = b * n;
                    a++
                } while (a <= k);
                input_element[2].value = b;
            }
            input_element[5].onclick = function () {
                var n = parseFloat(input_element[0].value);
                var k = parseFloat(input_element[1].value);
                var a = 1;
                for (var i = 1; i <= k; i++) {
                    a = a * n;
                }
                input_element[2].value = a;
            }
            input_element[6].onclick = function () {
                input_element[0].value = "";
                input_element[1].value = "";
                input_element[2].value = "";

            }
        }
    </script>
</head>

<body>
    <h2>求n的k次方</h2>
    <form action="">
        <input type="text" name="" id="" placeholder="请输入n">^
        <input type="text" name="" id="" placeholder="请输入k">=
        <input type="text" name="" id="" placeholder="结果">
        <input type="button" value="while">
        <input type="button" value="do-while">
        <input type="button" value="for">
        <input type="button" value="重置">

    </form>
</body>

</html>